/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pracamagisterska;

import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComponent;
import javax.swing.JDesktopPane;

/**
 *
 * @author Adrian
 */
public class Warning extends ModalityInternalFrame {

    private MainWindow mw = null;
    private JComponent parent;
    private DatabaseThread db = null;
    private boolean bln = false;

    /**
     * Creates new form Warning
     */
    public Warning(JComponent parent, String text) {
        super(parent, text);
        initComponents();
        jLabel1.setText(text);
        this.parent = parent;
    }

    public Warning(JComponent parent, String text, DatabaseThread db) {
        super(parent, text, db);
        initComponents();
        jLabel1.setText(text);
        this.parent = parent;
        this.db = db;
    }

    public Warning(JComponent parent, String text, DatabaseThread db, boolean x) {
        super(parent, text, db);
        initComponents();
        jLabel1.setText(text);
        this.parent = parent;
        this.db = db;
        this.bln = x;
    }

    public Warning(DatabaseThread db, MainWindow mw, String text) {
        initComponents();
        jLabel1.setText(text);
        this.mw = mw;
        this.db = db;
    }

    protected void init() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_alert.png"))); // NOI18N

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("jLabel1");

        jButton1.setText("OK");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Anuluj");
        jButton2.setMaximumSize(new java.awt.Dimension(47, 23));
        jButton2.setMinimumSize(new java.awt.Dimension(47, 23));
        jButton2.setPreferredSize(new java.awt.Dimension(47, 23));
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(66, 66, 66)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 232, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(36, 36, 36)
                                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(117, 117, 117)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(68, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(26, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        this.dispose();
        if (parent != null && parent instanceof ModalityInternalFrame) {
            ((ModalityInternalFrame) parent).childClosing();
        }
        if (parent == null) {
            db.MainWindow_unblockAll();
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        this.dispose();
        if (parent != null && parent instanceof ModalityInternalFrame) {
            try {
                if (parent instanceof PersonDetails) {
                    if (bln) {
                        if (db != null) {
                            ((PersonDetails) parent).childReviewClosing(true);
                        } else {
                            ((PersonDetails) parent).childReviewClosing(false);
                        }
                    } else {
                        if (db != null) {
                            ((PersonDetails) parent).childparentClosing(true);
                        } else {
                            ((PersonDetails) parent).childparentClosing(false);
                        }
                    }
                }                
                if (parent instanceof Review) {
                    ((Review) parent).childparentClosing();
                    ((Review) parent).childClosing();
                }
                if (parent instanceof Card) {
                    if (db != null) {
                        ((Card) parent).childparentClosing(true);
                        ((Card) parent).childClosing();
                    } else {

                        ((Card) parent).childparentClosing(false);
                        ((Card) parent).childClosing();
                    }
                }
            } catch (SQLException ex) {
                Logger.getLogger(Warning.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        if (parent == null) {
            try {
                mw.logout();
            } catch (SQLException ex) {
                Logger.getLogger(Warning.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_jButton1ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    // End of variables declaration//GEN-END:variables
}
